#include "stdio.h"
#include "string.h"
#include "math.h"
typedef struct student{
    char name[100];
    char num[100];
    int score;
}stu;


int main(){
    int n=0;
    stu arr[10001];
    scanf("%d",&n);
    getchar();
    for (int i = 0; i < n; ++i) {
        scanf("%s",arr[i].name);
        getchar();
        scanf("%s",arr[i].num);
        getchar();
        scanf("%d",&arr[i].score);
        getchar();
    }
//    qsort(arr,n,sizeof (arr[0]),cmp);
    int max_index=0;
    int min_index=0;
    for (int i = 1; i < n; ++i) {
        if(arr[i].score>arr[max_index].score){
            max_index = i;
        }
        if(arr[i].score<arr[min_index].score){
            min_index = i;
        }
    }
    printf("%s %s\n",arr[max_index].name,arr[max_index].num);
    printf("%s %s\n",arr[min_index].name,arr[min_index].num);
    return 0;
}